package com.ruoyi.project.erp.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.TokenConfig;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.erp.domain.Project;
import com.ruoyi.project.erp.domain.VersionPOJO;
import com.ruoyi.project.erp.service.IProjectService;
import com.ruoyi.project.erp.service.ITaskService;
import com.ruoyi.project.erp.service.IWorklogApprovalService;
import com.ruoyi.project.erp.service.IWorklogService;
import com.ruoyi.project.erp.vo.*;
import com.ruoyi.project.system.domain.SysUser;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@Slf4j
@RequestMapping("/app/user")
public class UserInfoController extends BaseController {
    @Autowired
    IProjectService projectService;

    @Autowired
    ITaskService taskService;

    @Autowired
    IWorklogService worklogService;

    @Autowired
    IWorklogApprovalService worklogApprovalService;


    @GetMapping("/getMyProject")
    public TableDataInfo getMyProject() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        // 启动分页
        startPage();
        List<MyProjectInfoVo> vos = projectService.getMyProject(user);
        return getDataTable(vos);
    }

    @GetMapping("/getMyTask")
    public TableDataInfo getMyTask() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        // 启动分页
        startPage();
        List<MyTaskInfoVo> vos = taskService.getMyTask(user);
        return getDataTable(vos);
    }

    @GetMapping("/getMyWorkLog")
    public TableDataInfo getMyWorkLog() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        // 启动分页
        startPage();
        List<MyWorkLogInfoVo> vos = worklogService.getMyWorkLog(user.getDdUserId());
        return getDataTable(vos);
    }

    @GetMapping("/queryMyApprovalList")
    public TableDataInfo queryMyApprovalList() {
        // 启动分页
        startPage();
        List<MyWorkLogApprovalVo> vos = worklogApprovalService.queryMyApprovalList();
        return getDataTable(vos);
    }


    @GetMapping("/mobileVer")
    public VersionPOJO getPhoneVer() {
        Integer versionName = 1;
        log.info("开始生成！");
        log.info("版本号是："+versionName);
        return new VersionPOJO("ht.zl", versionName, 100L, "http://49.7.230.17:5173/download/htWorkLogManage.apk");
    }
}